package cn.kgc.tangcco.cryptography;

import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Base64.Encoder;

import org.junit.Test;

/**
 * 
 * @author	李昊哲
 * @version 1.0<br>
  *  创建时间	2020年7月28日	下午7:59:54	
 */
public class Base64Test01 {
	@Test
	public void test01() {
		// 获取Base64的加密对象
		Encoder encoder = Base64.getEncoder();
		// 获取Base64的解密对象
		Decoder decoder = Base64.getDecoder();
		String content = "李昊哲";
		try {
			byte[] encode = encoder.encode(content.getBytes("UTF-8"));
			String encodeToString = encoder.encodeToString(content.getBytes("UTF-8"));
			System.out.println(new String(encode));
			System.out.println(encodeToString);
			
			byte[] decode1 = decoder.decode(encode);
			byte[] decode2 = decoder.decode(encodeToString);
			System.out.println(new String(decode1));
			System.out.println(new String(decode2));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
